﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Server.ServiceImplement
{
    public class DefaultSolutionFilterStategy:ISolutionFilterStrategy
    {
        public List<Core.Data.Solution> Filter(List<Core.Data.Solution> solutionList, CacheData.Client client)
        {
            List<Core.Data.Solution> usedSolutionList = new List<Core.Data.Solution>();
            if (client != null && solutionList != null)
            {

                if (client.AppType == "BrowseApp")
                {
                    //根据client的类型从solution列表中筛选出可以使用的solution列表
                    foreach (Core.Data.Solution solution in solutionList)
                    {
                        if (solution.Type == "APP")
                        {
                            usedSolutionList.Add(solution);
                        }
                    }
                }
                else
                {
                    //根据client的类型从solution列表中筛选出可以使用的solution列表
                    foreach (Core.Data.Solution solution in solutionList)
                    {
                        if (solution.Type == "SHOW")
                        {
                            usedSolutionList.Add(solution);
                        }
                    }
                }
            }
            return usedSolutionList;
        }

        public List<CPPEI.Coolzon.Metadata.SolutionRef> Filter(List<CPPEI.Coolzon.Metadata.SolutionRef> solutionList, string clientAppType)
        {
            List<CPPEI.Coolzon.Metadata.SolutionRef> usedSolutionList = new List<CPPEI.Coolzon.Metadata.SolutionRef>();
            if (solutionList != null)
            {

                if (clientAppType == "BrowseApp")
                {
                    //根据client的类型从solution列表中筛选出可以使用的solution列表
                    foreach (CPPEI.Coolzon.Metadata.SolutionRef solution in solutionList)
                    {
                        if (solution.Type == "APP")
                        {
                            usedSolutionList.Add(solution);
                        }
                    }
                }
                else
                {
                    //根据client的类型从solution列表中筛选出可以使用的solution列表
                    foreach (CPPEI.Coolzon.Metadata.SolutionRef solution in solutionList)
                    {
                        if (solution.Type == "SHOW")
                        {
                            usedSolutionList.Add(solution);
                        }
                    }
                }
            }
            return usedSolutionList;
        }
    }
}
